from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-30 14:12:58.040804
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 30, Aug, 2021
Time: 14:13:02
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.8802
Nobs: 399.000 HQIC: -46.4236
Log likelihood: 4327.19 FPE: 4.82806e-21
AIC: -46.7799 Det(Omega_mle): 3.86384e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.433765 0.094725 4.579 0.000
L1.Burgenland 0.103493 0.048961 2.114 0.035
L1.Kärnten -0.116046 0.024331 -4.769 0.000
L1.Niederösterreich 0.156098 0.104980 1.487 0.137
L1.Oberösterreich 0.138529 0.103444 1.339 0.181
L1.Salzburg 0.282644 0.051279 5.512 0.000
L1.Steiermark 0.026714 0.067969 0.393 0.694
L1.Tirol 0.109311 0.053700 2.036 0.042
L1.Vorarlberg -0.117034 0.048530 -2.412 0.016
L1.Wien -0.010463 0.093490 -0.112 0.911
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.022942 0.219904 0.104 0.917
L1.Burgenland -0.044619 0.113664 -0.393 0.695
L1.Kärnten 0.036566 0.056485 0.647 0.517
L1.Niederösterreich -0.251371 0.243710 -1.031 0.302
L1.Oberösterreich 0.527115 0.240146 2.195 0.028
L1.Salzburg 0.309903 0.119045 2.603 0.009
L1.Steiermark 0.115684 0.157789 0.733 0.463
L1.Tirol 0.307349 0.124663 2.465 0.014
L1.Vorarlberg -0.006685 0.112663 -0.059 0.953
L1.Wien -0.005496 0.217037 -0.025 0.980
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.254636 0.048313 5.271 0.000
L1.Burgenland 0.087540 0.024972 3.506 0.000
L1.Kärnten -0.002314 0.012410 -0.186 0.852
L1.Niederösterreich 0.207278 0.053543 3.871 0.000
L1.Oberösterreich 0.171072 0.052760 3.242 0.001
L1.Salzburg 0.037819 0.026154 1.446 0.148
L1.Steiermark 0.016436 0.034666 0.474 0.635
L1.Tirol 0.062315 0.027388 2.275 0.023
L1.Vorarlberg 0.059904 0.024752 2.420 0.016
L1.Wien 0.106441 0.047683 2.232 0.026
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180045 0.047027 3.829 0.000
L1.Burgenland 0.046859 0.024307 1.928 0.054
L1.Kärnten -0.007384 0.012079 -0.611 0.541
L1.Niederösterreich 0.137503 0.052118 2.638 0.008
L1.Oberösterreich 0.317706 0.051355 6.186 0.000
L1.Salzburg 0.098839 0.025458 3.882 0.000
L1.Steiermark 0.134571 0.033743 3.988 0.000
L1.Tirol 0.077280 0.026659 2.899 0.004
L1.Vorarlberg 0.054001 0.024093 2.241 0.025
L1.Wien -0.039760 0.046414 -0.857 0.392
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209035 0.093725 2.230 0.026
L1.Burgenland -0.060669 0.048445 -1.252 0.210
L1.Kärnten -0.035251 0.024074 -1.464 0.143
L1.Niederösterreich 0.123367 0.103872 1.188 0.235
L1.Oberösterreich 0.174075 0.102353 1.701 0.089
L1.Salzburg 0.258492 0.050738 5.095 0.000
L1.Steiermark 0.078618 0.067251 1.169 0.242
L1.Tirol 0.122843 0.053133 2.312 0.021
L1.Vorarlberg 0.111538 0.048018 2.323 0.020
L1.Wien 0.022202 0.092503 0.240 0.810
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.025807 0.073023 0.353 0.724
L1.Burgenland 0.026463 0.037744 0.701 0.483
L1.Kärnten 0.051203 0.018757 2.730 0.006
L1.Niederösterreich 0.210833 0.080928 2.605 0.009
L1.Oberösterreich 0.336715 0.079744 4.222 0.000
L1.Salzburg 0.045000 0.039531 1.138 0.255
L1.Steiermark -0.001844 0.052396 -0.035 0.972
L1.Tirol 0.114536 0.041396 2.767 0.006
L1.Vorarlberg 0.062849 0.037412 1.680 0.093
L1.Wien 0.129432 0.072071 1.796 0.073
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189240 0.088926 2.128 0.033
L1.Burgenland 0.018982 0.045964 0.413 0.680
L1.Kärnten -0.059836 0.022842 -2.620 0.009
L1.Niederösterreich -0.132653 0.098553 -1.346 0.178
L1.Oberösterreich 0.196062 0.097111 2.019 0.043
L1.Salzburg 0.027608 0.048140 0.574 0.566
L1.Steiermark 0.303579 0.063807 4.758 0.000
L1.Tirol 0.491285 0.050412 9.745 0.000
L1.Vorarlberg 0.070108 0.045559 1.539 0.124
L1.Wien -0.101610 0.087766 -1.158 0.247
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160560 0.096784 1.659 0.097
L1.Burgenland -0.004292 0.050026 -0.086 0.932
L1.Kärnten 0.063302 0.024860 2.546 0.011
L1.Niederösterreich 0.201008 0.107262 1.874 0.061
L1.Oberösterreich -0.123831 0.105693 -1.172 0.241
L1.Salzburg 0.241846 0.052394 4.616 0.000
L1.Steiermark 0.153321 0.069446 2.208 0.027
L1.Tirol 0.051325 0.054867 0.935 0.350
L1.Vorarlberg 0.122130 0.049585 2.463 0.014
L1.Wien 0.137552 0.095522 1.440 0.150
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.487923 0.052437 9.305 0.000
L1.Burgenland -0.011540 0.027104 -0.426 0.670
L1.Kärnten -0.010178 0.013469 -0.756 0.450
L1.Niederösterreich 0.203380 0.058114 3.500 0.000
L1.Oberösterreich 0.260928 0.057264 4.557 0.000
L1.Salzburg 0.021442 0.028387 0.755 0.450
L1.Steiermark -0.024235 0.037626 -0.644 0.520
L1.Tirol 0.069814 0.029727 2.349 0.019
L1.Vorarlberg 0.058090 0.026865 2.162 0.031
L1.Wien -0.052823 0.051753 -1.021 0.307
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.017500 0.075151 0.134917 0.130241 0.039724 0.067378 0.002074 0.175016
Kärnten 0.017500 1.000000 -0.054646 0.128677 0.047042 0.070763 0.457290 -0.093363 0.095997
Niederösterreich 0.075151 -0.054646 1.000000 0.281650 0.081718 0.271315 0.015064 0.149391 0.246983
Oberösterreich 0.134917 0.128677 0.281650 1.000000 0.178250 0.287216 0.159457 0.114832 0.139426
Salzburg 0.130241 0.047042 0.081718 0.178250 1.000000 0.127153 0.058195 0.107739 0.050233
Steiermark 0.039724 0.070763 0.271315 0.287216 0.127153 1.000000 0.130390 0.088836 -0.024399
Tirol 0.067378 0.457290 0.015064 0.159457 0.058195 0.130390 1.000000 0.041731 0.117758
Vorarlberg 0.002074 -0.093363 0.149391 0.114832 0.107739 0.088836 0.041731 1.000000 -0.047715
Wien 0.175016 0.095997 0.246983 0.139426 0.050233 -0.024399 0.117758 -0.047715 1.000000